package com.kxmall.admin.controller.vehicle;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.kxmall.admin.controller.vehicle.service.IKxVehicleBoxDownGoodsService;
import com.kxmall.common.annotation.Log;
import com.kxmall.common.annotation.RepeatSubmit;
import com.kxmall.common.core.controller.BaseController;
import com.kxmall.common.core.domain.PageQuery;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.core.page.TableDataInfo;
import com.kxmall.common.core.validate.AddGroup;
import com.kxmall.common.core.validate.EditGroup;
import com.kxmall.common.enums.BusinessType;
import com.kxmall.common.utils.poi.ExcelUtil;
import com.kxmall.vehicle.domain.bo.KxVehicleBoxOutGoodsBo;
import com.kxmall.vehicle.domain.vo.KxVehicleBoxDownGoodsVo;
import com.kxmall.vehicle.domain.vo.KxVehicleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 商品出柜
 */
@Slf4j
@Api(tags = "商品出柜")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/vehicle/box/goodsDownVehicleBox")
public class KxVehicleBoxDownGoodsController extends BaseController {

    private final IKxVehicleBoxDownGoodsService iKxGoodsDownVehicleBoxService;

    /**
     * 导出商品出柜列表
     */
    @SaIgnore
    @PostMapping("/listAll")
    @ApiOperation(value = "/vehicle/box/goodsDownVehicleBox/listAll - 导出商品出柜列表", httpMethod = "POST")
    public R<List<KxVehicleBoxDownGoodsVo>> listAll(KxVehicleBoxOutGoodsBo bo, HttpServletResponse response) {
        List<KxVehicleBoxDownGoodsVo> list = iKxGoodsDownVehicleBoxService.queryList(bo);
        log.info(list.toString());
        return R.ok(list);
    }

    /**
     * 查询商品出柜列表
     */
    @SaCheckPermission("vehicle:box:goodsDownVehicleBox:pageList")
    @ApiOperation(value = "/vehicle/box/goodsDownVehicleBox/pageList - 查询商品出柜列表", httpMethod = "GET")
    @GetMapping("/pageList")
    public TableDataInfo<KxVehicleBoxDownGoodsVo> pageList(KxVehicleBoxOutGoodsBo bo, PageQuery pageQuery) {
        TableDataInfo<KxVehicleBoxDownGoodsVo> infoList = iKxGoodsDownVehicleBoxService.queryPageList(bo, pageQuery);
        log.info(infoList.toString());
        return infoList;
    }

    /**
     * 导出商品出柜列表
     */
    @SaCheckPermission("vehicle:box:goodsDownVehicleBox:export")
    @Log(title = "导出商品出柜列表", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "/vehicle/box/goodsDownVehicleBox/export - 导出商品出柜列表", httpMethod = "POST")
    @PostMapping("/export")
    public void export(KxVehicleBoxOutGoodsBo bo, HttpServletResponse response) {
        List<KxVehicleBoxDownGoodsVo> list = iKxGoodsDownVehicleBoxService.queryList(bo);
        log.info(list.toString());
        ExcelUtil.exportExcel(list, "商品出库", KxVehicleBoxDownGoodsVo.class, response);
    }

    /**
     * 获取商品出柜详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("vehicle:box:goodsDownVehicleBox:query")
    @ApiOperation(value = "/vehicle/box/goodsDownVehicleBox/query/{id} - 获取商品出柜详细信息", httpMethod = "GET")
    @GetMapping("/query/{id}")
    public R<KxVehicleBoxDownGoodsVo> query(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        KxVehicleBoxDownGoodsVo kxVehicleBoxDownGoodsVo = iKxGoodsDownVehicleBoxService.queryById(id);
        log.info(kxVehicleBoxDownGoodsVo.toString());
        return R.ok(kxVehicleBoxDownGoodsVo);
    }

    /**
     * 新增商品出柜
     */
    @SaCheckPermission("vehicle:box:goodsDownVehicleBox:add")
    @Log(title = "新增商品出柜", businessType = BusinessType.INSERT)
    @ApiOperation(value = "/vehicle/box/goodsDownVehicleBox/add - 新增商品出柜", httpMethod = "POST")
    @PostMapping("/add")
    @RepeatSubmit()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody KxVehicleBoxOutGoodsBo bo) {
        return toAjax(iKxGoodsDownVehicleBoxService.insertByBo(bo));
    }

    /**
     * 修改商品出柜
     */
    @SaCheckPermission("vehicle:box:goodsDownVehicleBox:edit")
    @Log(title = "修改商品出柜", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "/vehicle/box/goodsDownVehicleBox/edit - 修改商品出柜", httpMethod = "PUT")
    @PutMapping("/edit")
    @RepeatSubmit()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody KxVehicleBoxOutGoodsBo bo) {
        return toAjax(iKxGoodsDownVehicleBoxService.updateByBo(bo));
    }

    /**
     * 删除商品出柜
     *
     * @param ids 主键串
     */
    @SaCheckPermission("vehicle:box:goodsDownVehicleBox:remove")
    @Log(title = "删除商品出柜", businessType = BusinessType.DELETE)
    @ApiOperation(value = "/vehicle/box/goodsDownVehicleBox/remove/{ids} - 删除商品出柜", httpMethod = "DELETE")
    @DeleteMapping("/remove/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iKxGoodsDownVehicleBoxService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


    /**
     * 出柜
     */
    @ApiOperation(value = "/vehicle/box/goodsDownVehicleBox/updateDownVehicleBox - 出柜", httpMethod = "POST")
    @PostMapping("/updateDownVehicleBox")
    @RepeatSubmit()
    public R<Boolean> updateDownVehicleBox(@Validated(AddGroup.class) @RequestBody KxVehicleBoxOutGoodsBo bo) {
        return R.ok(iKxGoodsDownVehicleBoxService.updateDownVehicleBox(bo));
    }


    /**
     * 获取所有餐车的名称
     */
    @ApiOperation(value = "/vehicle/box/goodsDownVehicleBox/vehicleAllName - 获取所有餐车的名称", httpMethod = "POST")
    @PostMapping("vehicleAllName")
    @RepeatSubmit()
    public R<List<KxVehicleVo>>vehicleAllName(@Validated(AddGroup.class) @RequestBody KxVehicleBoxOutGoodsBo bo) {
        return R.ok(iKxGoodsDownVehicleBoxService.vehicleAllName(bo));
    }
}
